package indy.test.indy;

import java.lang.invoke.CallSite;
import java.lang.invoke.ConstantCallSite;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.invoke.MethodHandles.Lookup;

public class HelloIndyTemplate {
    public static void say(String text1, String text2) {
        System.out.println(text1+" "+text2);
    }
    
    public static void main(String[] args) throws Throwable {
        indy("invokedynamic");
    }
    
    
    private static void indy(String message) {
        throw new AssertionError(message);
    }

    public static CallSite bsm(Lookup lookup, String name, MethodType type, String text) throws Throwable {
        MethodHandle mh = lookup.findStatic(HelloIndyTemplate.class, name,
                MethodType.methodType(void.class, String.class, String.class));
        
        mh = MethodHandles.insertArguments(mh, 0, text);
        
        if (!mh.type().equals(type)) {
            throw new AssertionError();
        }
        
        return new ConstantCallSite(mh);
    }
}
